package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.OrderSettingDao;
import com.itheima.pojo.OrderSetting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

/**
 * @author nglsk
 * @version v1.0
 * @date 2019/11/25 11:46
 * @description TODO
 **/
@Transactional
@Service(interfaceClass = OrderSettingService.class)
public class OrderSettingServiceImpl implements OrderSettingService {


    @Autowired
    private OrderSettingDao orderSettingDao;

    /**
     * 设置可预约人数
     *
     * @param orderSetting
     */
    @Override
    public void setNumberByDate(OrderSetting orderSetting) {
        //获取预约日期
        Date orderDate = orderSetting.getOrderDate();
        //先查询当前日期是否已存在预约设置，
        Integer count = orderSettingDao.findCountByDate(orderDate);

        //如果存在，则修改预约设置
        if (null != count && count > 0) {
            orderSettingDao.edit(orderSetting);
        } else {
            //如果不存在，则新增预约
            orderSettingDao.add(orderSetting);
        }

    }


    /**
     * 批量设置可预约人数
     *
     * @param orderSettings
     */
    @Override
    public void setNumberByDateBatch(List<OrderSetting> orderSettings) {
        for (OrderSetting orderSetting : orderSettings) {
            setNumberByDate(orderSetting);
        }
    }
}
